package com.autcar.training.service;

import com.autcar.training.dao.CustomerMapper;
import com.autcar.training.entity.Customer;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName: training
 * @Package: com.autcar.training.service
 * @ClassName: customerServiceImpl
 * @Author: YHHHH
 * @Description:
 * @Date: 2020/8/27 22:00
 * @Version: 1.0
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Resource
    private CustomerMapper customerMapper;

    //增加客户
    @Override
    public int addCustomer(Customer customer) {
        return customerMapper.insert(customer);
    }


    //删除客户
    @Override
    public int deleteCustomer(Integer id) {
        return customerMapper.deleteById(id);
    }

    //根据ID查询用户
    @Override
    public Customer selectById(Integer id) {
        return customerMapper.selectById(id);
    }


    //根据姓名模糊查询客户
    @Override
    public List<Customer> selectByName(String name) {
        return customerMapper.selectList(new QueryWrapper<Customer>().like("name",name));
    }


    //根据ID更新用户
    @Override
    public int updateCustomer(Customer customer) {
        return customerMapper.updateById(customer);
    }

    //查询所有客户
    @Override
    public List<Customer> findAllCustomer() {
        return customerMapper.selectList(null);//为null查询全部
    }



}
